<?php

namespace app\admin\service\statistics\datatable\lawsuit;


use app\admin\service\statistics\datatable\AbstractComputeStatistician;
use app\admin\service\statistics\traits\CompletionTrait;


/**
 * 完成第2步占比
 * Class LawsuitStep2Rate
 * @package app\admin\service\statistics\datatable\lawsuit
 */
class LawsuitStep2Rate extends AbstractComputeStatistician
{
    // 前置数据
    protected array $statisticians = [
        'uv' => LawsuitUvCount::class,
        'lawsuit_step2_count' => LawsuitStep2Count::class,
    ];

    // 补齐
    use CompletionTrait;

    protected function compute(int $index)
    {
        $statisticiansData = $this->statisticiansData;

        $uv = $statisticiansData['uv'][$index]['value'] ?? null;

        $lawsuit_step2_count = $statisticiansData['lawsuit_step2_count'][$index]['value'] ?? null;

        if (!is_numeric($uv) || !is_numeric($lawsuit_step2_count)) {
            return '';
        }

        return show_percentage($lawsuit_step2_count, $uv, 1);
    }

    protected function getDefaultValue()
    {
        return '0%';
    }
}